Jump to content

Module:Gl-noun

Frae Wikipedia, the free beuk o knawledge
local m_plural = require("Module:gl-plural")

local export = {}

local lang = require("Module:languages").getByCode("gl")

function export.show(frame)
	local args = frame:getParent().args
	PAGENAME = mw.title.getCurrentTitle().text
	NAMESPACE = mw.title.getCurrentTitle().nsText
	
	local data = {lang = lang, pos_category = "nouns", categories = {}, heads = {args["head"]}, genders = {}, inflections = {}}
	
	-- Genders
	local is_plural = false
	local g1 = args[1]; if g1 == "" then g1 = nil end
	local g2 = args["g2"]; if g2 == "" then g2 = nil end
	
	g1 = g1 or "?"
	
	if g1 == "morf" or g1 == "mf" or g1 == "c" then
		g1 = "m"
		g2 = "f"
	end
	
	if g2 == "morf" or g2 == "mf" or g2 == "c" then
		error("g2 can't be mf, morf or c!")
	end
	
	data.genders = {g1}
	
	if g2 then
		table.insert(data.genders, g2)
		table.insert(data.categories, lang:getCanonicalName() .. " nouns with varying gender")
	end
	
	if g1:find("p") or (g2 and g2:find("p")) then
		table.insert(data.categories, lang:getCanonicalName() .. " pluralia tantum")
		is_plural = true
	end
	
	-- for compatibility with pt-noun
	if (args[2] == "s") then
		args[2] = PAGENAME .. "s"
	elseif (args[2] == "es") then
		args[2] = PAGENAME .. "es"
	end
	
	if not is_plural then
		local par2 = args[2]; if par2 == "" then par2 = nil end
		local parpl = args["pl"]; if parpl == "" then parpl = nil end
		local unc = args["unc"] ~= nil
		
		if not par2 then
			par2 = parpl
		end
		
		if par2 == "-" then
			table.insert(data.inflections, {label = "uncountable"})
		else
			if unc then
				table.insert(data.inflections, {label = "usually uncountable"})
			end
			
			local plurals = {label = "plural", accel = "plural-form-of", request = true}
			
			if par2 ~= "?" then
				if not par2 then
					par2 = m_plural.get_plural(PAGENAME)
				end
			
				if par2 then
					table.insert(plurals, par2)
					
					local parpl2 = args["pl2"]; if parpl2 == "" then parpl2 = nil end
					local parpl3 = args["pl3"]; if parpl3 == "" then parpl3 = nil end
					
					if parpl2 then
						table.insert(data.categories, lang:getCanonicalName() .. " terms with multiple plurals")
						table.insert(data.plurals, parpl2)
					end
					
					if parpl3 then
						table.insert(data.categories, lang:getCanonicalName() .. " terms with multiple plurals")
						table.insert(data.plurals, parpl3)
					end
				end
				
				table.insert(data.inflections, plurals)
			end
		end
	end
	
	local parf = args["f"]; if parf == "" then parf = nil end
	local parf2 = args["f2"]; if parf2 == "" then parf2 = nil end
	local parfpl = args["fpl"]; if parfpl == "" then parfpl = nil end
	local parfpl2 = args["fpl2"]; if parfpl2 == "" then parfpl2 = nil end
	
	local feminines = {label = "feminine"}
	local feminine_plurals = {label = "feminine plural"}
	
	if parf then
		table.insert(feminines, parf)
		
		if not is_plural then
			if not parfpl then
				parfpl = m_plural.get_plural(parf)
			end
			
			table.insert(feminine_plurals, parfpl)
		end
		
		if parf2 then
			table.insert(feminines, parf2)
			
			if not is_plural then
				if not parfpl2 then
					parfpl2 = m_plural.get_plural(parf2)
				end
			
				table.insert(feminine_plurals, parfpl)
			end
		end
		
		table.insert(data.inflections, feminines)
		
		if not is_plural then
			table.insert(data.inflections, feminine_plurals)
		end
	end
	
	if args["qual_g1"] or args["qual_g2"] or args["qual_pl"] or args["qual_pl2"] or args["qual_pl3"] or args["qual_f"] or args["qual_fpl"] or args["qual_f2"] or args["qual_fpl2"] then
		require("Module:debug").track("gl-noun wi qualifier")
	end
	
	return require("Module:headword").full_headword(data)
end


return export